package cn.gx.kevin.domain;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/***
 *@description :
 *@author : kevin.huang
 *@date : 2019/10/26 15:50
 @modified by
 ***/
public class DynamicSelectParam extends  DynamicBaseWhereParam{

    private LinkedList<String> orderList = new LinkedList<String>();

    /***设置排序字段***/
    public DynamicSelectParam setOrder(String fieldName,String order){
        fieldName = this.replaceIllegalChars(fieldName);
        if("asc".equals(order) || "desc".equals(order)){
            orderList.add(fieldName+" "+order);
        }
        return this;
    }

    public String getOrderColumn() {
        StringBuilder builder = new StringBuilder();
        for(int i = 0 ,len = orderList.size() ; i < len ;++i){
            builder.append(orderList.get(i));
            if(i < len - 1){
                builder.append(",");
            }
        }
        orderColumn = builder.toString();
        if(orderColumn.equals("")){
            return null;
        }
        return orderColumn;
    }

    /*****排序的字段****/
    String orderColumn;

    /*****查询的字段****/
    List<String> selectFields;


    /*****查询的字段****/
    public List<String> getSelectFields() {
        return selectFields;
    }
    /*****查询的字段****/
    public void setSelectFields(List<String> selectFields) {
        List<String> newList = new ArrayList<>();
        for(String s : selectFields ){
            newList.add(this.replaceIllegalChars(s));
        }
        this.selectFields = newList;
    }

}
